package main

import "fmt"


func test() func() int{
	var b int
	return func() int {
		b++
		return b*b
	}
}


func main(){

	a := 10
	str := `aaa`
	//闭包函数是以引用的方式调用
	func(){
		a = 20
		str = "bbb"

	}()
	//结果 a=20,str=bbb
	fmt.Printf("a=%d,str=%v\n",a,str)

	f := test()
	fmt.Println(f())
	fmt.Println(f())
	fmt.Println(f())
	f = test()
	fmt.Println(f())

}
